package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.BaseUserRole;
import com.briup.jz.bean.extend.BaseUserExtend;
import com.briup.jz.service.BaseUserRoleService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="用户角色表")
@Validated
@RestController
@RequestMapping("/baseUserRole")
public class BaseUserRoleController {
	
	@Autowired
    private BaseUserRoleService baseUserRoleService;
	
	@ApiOperation(value = "查询所有用户角色")
    @GetMapping("query")
	//根据id查询用户角色
    public Message query(Long Id){
        List<BaseUserRole> list = baseUserRoleService.query(Id);
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id删除用户角色")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
    	baseUserRoleService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新用户角色信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="userId",value = "用户Id",paramType = "form",required = true),
            @ApiImplicitParam(name="roleId",value = "角色Id",paramType = "form",required = true),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BaseUserRole baseUserRole){
    	baseUserRoleService.saveOrUpdate(baseUserRole);
        return MessageUtil.success("更新成功");
    }
    @PostMapping("updateByUserId")
    public Message updateByUserId(Long userId,Long roleId) {
    	baseUserRoleService.updateByUserId(userId, roleId);
        return MessageUtil.success("修改成功");
    }
}
